#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project : python的学习
@File    : 进程与线程.py
@IDE     : PyCharm
@Author  : 春风十里
@Date    : 2023/6/27 15:23

'''
# import time
# import multiprocessing
# import os
#
#
# def music():
#     print("music子进程名字:", multiprocessing.current_process)
#     print("music子进程编号:", os.getpid())
#     print("music所属主进程的编号:", os.getpid())
#     for i in range(5):
#         print("听音乐中...")
#         time.sleep(0.2)
#
#
# def movie(a, b):
#     print("movie子进程名字:", multiprocessing.current_process())
#     print("movie子进程编号:", os.getpid())
#     print("movie所属主进程的编号:", os.getpid())
#     for i in range(5):
#         print("看视频中...")
#         time.sleep(0.2)
#
#
# if __name__ == "__main__":
#     music_process = multiprocessing.Process(target=music)
#     movie_process = multiprocessing.Process(target=movie, kwargs={"a": 30, "b": 40})
#
#     music_process.start()
#     movie_process.start()
#
#     print("主进程执行完毕", os.getpid())

import threading, time


def music(name, loop):
    for i in range(loop):
        print("听音乐 %s, 第%s次" % (name, i))
        time.sleep(0.2)


def movie(name, loop):
    for i in range(loop):
        print("看电影%s , 第%s次" % (name, i))
        time.sleep(0.2)


if __name__ == "__main__":
    music_thread = threading.Thread(target=music, args=("最亲的人", 3))
    movie_thread = threading.Thread(target=movie, args=("唐探2", 3))
    music_thread.start()
    movie_thread.start()
    print("主程序执行完毕")

import threading, time


class MyThread(threading.Thread):
    def __init__(self, name):
        super().__init__()
        self.name = name

    def run(self):
        for i in range(5):
            print(self.name)
            time.sleep(0.2)


t1 = MyThread("风吹一下")
t2 = MyThread("代码改变世界")
t1.start()
t2.start()

